package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class P1186 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1186.class.getResource("P1186.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		StringTokenizer st = null;
		int n = Integer.valueOf(stdin.readLine().trim());
		int M = Integer.valueOf(stdin.readLine().trim());
		int[] k = new int[n];
		int[] p = new int[n];
		for (int i = 0; i < n; i ++) {
			st = new StringTokenizer(stdin.readLine());
			k[i] = Integer.valueOf(st.nextToken());
			p[i] = Integer.valueOf(st.nextToken());
		}
		
		int s = n/2;
		int[] k1 = new int[s];
		System.arraycopy(k, 0, k1, 0, s);
		int[] p1 = new int[s];
		System.arraycopy(p, 0, p1, 0, s);
		int min1 = 0, max1 = 0;
		for (int i = 0; i < k1.length; i ++) {
			if (k1[i] >= 0) {
				min1 += k1[i]; 
				max1 += k1[i]*Math.pow(M, p1[i]);
			} else {
				min1 += k1[i]*Math.pow(M, p1[i]);
				max1 += k1[i];
			}
		}
		
		int[] k2 = new int[n-s];
		System.arraycopy(k, s, k2, 0, n-s);
		int[] p2 = new int[n-s];
		System.arraycopy(p, s, p2, 0, n-s);
		int min2 = 0, max2 = 0;
		for (int i = 0; i < k2.length; i ++) {
			if (k2[i] >= 0) {
				min2 += k2[i]; 
				max2 += k2[i]*Math.pow(M, p2[i]);
			} else {
				min2 += k2[i]*Math.pow(M, p2[i]);
				max2 += k2[i];
			}
		}
		//缩小记录范围，不然容易出现MLE
		final int min = Math.max(min1, -max2);
		final int max = Math.min(max1, -min2);
		
		/*
		 * 计算所有可能的k*x^p之和, i<= n/2
		 * 保存在散列表中
		 */
		final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		iter(k1, p1, M, new Function() {

			public void execute(Object... args) {
				Integer n = (Integer)args[0];
				if (n >= min && n <= max) {
					Integer c = map.get(n);
					if (c == null) {
						map.put(n, 1);
					} else {
						map.put(n, c+1);
					}
				}
			}
		});
		/*
		 * 计算所有可能的k*x^p之和, i > n/2
		 * 并在散列表中查找计数
		 */
		final int[] c = new int[1];
		iter(k2, p2, M, new Function() {

			public void execute(Object... args) {
				Integer x = map.get(-(Integer)args[0]);
				if (x != null) {
					c[0] += x;
				}
			}
			
		});
		System.out.println(c[0]);
	}
	
	private static void iter(int[] k, int[] p, int M, Function func) {

		int s = k.length; 
		int[] a = new int[s];
		for (int i = 0; i < s; i ++) {
			a[i] = 1;
		}
		while (true) {
			if (s > 0 && a[s-1] <= M) {
				int r = 0;
				for (int i = 0; i < s; i ++) {
					r += k[i]*Math.pow(a[i], p[i]);
				}
				func.execute(r);
				a[s-1] ++;
			} else {
				int i = s-1;
				while (i > -1) {
					if (a[i] < M) {
						a[i] ++;
						break;
					} else {
						a[i]= 1;
					}
					i --;
				}
				if (i < 0) {
					break;
				}
			}
		}
	}
	
	private static interface Function {
		public void execute(Object... args);
	}
}